<template>
  <div class="table-box">
    <ProTable ref="pTable" :columns="columns" :init-param="initParam" :request-api="getTableList">
      <template #tableHeader>
        <el-button type="primary" :icon="CirclePlus" @click="handleOpenDialog(OptEnum.CREATE)"> 提现申请 </el-button>
      </template>
      <template #status="scope">
        <el-tag :type="scope.row.status === sysEnum.EIGHT ? '' : 'info'">
          {{ filterEnum(scope.row.status, cashStatusType) }}
        </el-tag>
      </template>
      <template #billStatus="scope">
        <el-tag :type="scope.row.billStatus === sysEnum.EIGHTEEN ? '' : 'info'">
          {{ filterEnum(scope.row.billStatus, billStatusType) }}
        </el-tag>
      </template>
      <template #operation="scope">
        <el-button type="primary" size="small" :icon="EditPen" @click="handleOpenDialog(OptEnum.EDIT, scope.row)">修改</el-button>
        <el-button type="danger" size="small" :icon="Delete" @click="handleDeleteItem(scope.row)">删除</el-button>
      </template>
    </ProTable>
    <DealerCashDialog ref="dialogRef" @refresh-list="handleRefreshList" />
  </div>
</template>
<script setup lang="ts">
import { ref, reactive } from "vue";
import ProTable from "@/components/ProTable/index.vue";
import { CirclePlus, Delete, EditPen } from "@element-plus/icons-vue";
import { getDealerCashVoListApi, deleteDealerCashApi } from "@/api/modules/dealer/cash";
import { ColumnProps } from "@/components/ProTable/interface";
import { useHandleData } from "@/hooks/useHandleData";
import { OptEnum, sysEnum } from "@/biz/eenum/appEnum";
import { cashStatusType, billStatusType } from "@/biz/eenum/statusEnum";
import { DealerCashVo } from "@/biz/interface/modules/DealerCashType";
import DealerCashDialog from "./components/DealerCashDialog.vue";
import { filterEnum } from "@/utils";

const pTable = ref();
// 固定在列表中的参数
const initParam = reactive({});
// 默认不做操作就直接在 ProTable 组件上绑定	:requestApi="getUserList"
const getTableList = (params: any) => {
  // 这边可以处理一下参数
  return getDealerCashVoListApi(params);
};
// 表格列配置
const columns: Partial<ColumnProps>[] = [
  { type: "index", label: "#", width: 60 },
  {
    prop: "payNo",
    label: "提现编号"
  },
  {
    prop: "payAmt",
    label: "提现金额"
  },
  {
    prop: "optDate",
    label: "提现日期"
  },
  {
    prop: "status",
    label: "状态"
  },
  {
    prop: "billStatus",
    label: "开票状态"
  },
  {
    prop: "payNote",
    label: "备注"
  },
  {
    prop: "settleDay",
    label: "到帐日期"
  },
  {
    prop: "cardNo",
    label: "到帐卡号"
  },
  {
    prop: "bankName",
    label: "到账银行"
  },
  {
    prop: "operation",
    width: 200,
    fixed: "right",
    label: "操作"
  }
];

//刷新数据列表
const handleRefreshList = () => {
  pTable.value.getTableList();
};

// 删除信息
const handleDeleteItem = async (params: DealerCashVo) => {
  await useHandleData(deleteDealerCashApi, { id: params.id! }, `删除【${params.payAmt}】信息`);
  pTable.value.getTableList();
};

// 打开 dialog(新增、查看、编辑)
const dialogRef = ref();
const handleOpenDialog = (optType: OptEnum, rowData?: { id: string }) => {
  let params = {
    optType: optType,
    rowData: { ...rowData }
  };
  dialogRef.value.acceptParams(params);
};
</script>
